package it.okkam.longwell.ui.command;

import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import org.apache.log4j.Logger;
import org.apache.velocity.VelocityContext;
import edu.mit.simile.longwell.login.CheckLogin;
import edu.mit.simile.longwell.ui.FlairMessage;
import edu.mit.simile.longwell.ui.InjectionManager;
import edu.mit.simile.longwell.ui.command.CommandBase;

/**
 * 
 * Create certificate with a webid
 *
 */

public class CreateCertificateCommand extends CommandBase {
	final static private Logger s_logger = Logger.getLogger(CreateCertificateCommand.class);
	CheckLogin check=null;
	final protected String m_template;
	public static boolean userInput = false;
	protected ServletContext 	context;
	VelocityContext vcContext = null;
	HashMap<String, String> userForSession = new HashMap<String, String>();
	/**
	 * @param injectionManager
	 */
	public CreateCertificateCommand(InjectionManager injectionManager, String template) {
		super(injectionManager);
		m_template = template;
	}

	/* (non-Javadoc)
	 * @see edu.mit.simile.flair.IFlairCommand#execute(edu.mit.simile.flair.FlairMessage)
	 */
	public void execute(FlairMessage msg) throws ServletException {
		try {
			vcContext = createContext(msg);
			msg.m_ve.mergeTemplate(
				m_template,
				vcContext,
				msg.m_response.getWriter());			
		} catch (Exception e) {
			s_logger.error(e);
			e.printStackTrace();
		}
	}
}	
